import uniCopy from '@/lib/js/uni-copy';
import {
	toast
} from './dailog'

export function goPage(url) {
	if (~url.indexOf('http')) {
		location.href = url
	} else {
		uni.navigateTo({
			url,
			fail() {
				uni.redirectTo({
					url,
					fail() {
						uni.switchTab({
							url,
							fail() {
								uni.reLaunch({
									url,
								});
							},
						});
					},
				});
			},
		});
	}
}

export function copy(content, cb) {
	uniCopy({
		content,
		success: () => {
			if (cb) {
				cb()
			} else {
				toast('复制成功')
			}
		}
	})
}

export function delay(time) {
	return new Promise((resolve) => setTimeout(resolve, time))
}
